package com.rstrulak.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.rstrulak.core.dao.GenericDaoImpl;
import com.rstrulak.model.Project;
import com.rstrulak.model.User;
import com.rstrulak.model.UserProject;

@Repository("userProjectDao")
public class UserProjectDaoImpl extends GenericDaoImpl<UserProject, Long> implements UserProjectDao {

	@Override
	public List<UserProject> getProjectListByUser(User user) {
		DetachedCriteria criteria = createDetachedCriteria();
		criteria.add(Restrictions.eq("user", user));
		return getListByCriteria(criteria);
	}

	@Override
	public List<UserProject> getUserListByProject(Project project, User user) {
		DetachedCriteria criteria = createDetachedCriteria();
		criteria.add(Restrictions.eq("project", project));
		criteria.add(Restrictions.ne("user", user));
		return getListByCriteria(criteria);
	}

	@Override
	public List<UserProject> getAllUserListByProject(Project project) {
		DetachedCriteria criteria = createDetachedCriteria();
		criteria.add(Restrictions.eq("project", project));
		return getListByCriteria(criteria);
	}

}
